home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / include / python2.4 / Numeric / arrayobject.h next >
Encoding:
C/C++ Source or Header  |  2006-01-20  |  14.1 KB  |  402 lines

  1.  
  2. #ifndef Py_ARRAYOBJECT_H
  3. #define Py_ARRAYOBJECT_H
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7.  
  8. #define REFCOUNT(obj) (((PyObject *)(obj))->ob_refcnt)
  9. #define MAX_ELSIZE 16
  10.  
  11. #define PyArray_UNSIGNED_TYPES
  12.  
  13. enum PyArray_TYPES {    PyArray_CHAR, PyArray_UBYTE, PyArray_SBYTE,
  14.                 PyArray_SHORT, PyArray_USHORT, 
  15.                 PyArray_INT, PyArray_UINT, 
  16.             PyArray_LONG,
  17.             PyArray_FLOAT, PyArray_DOUBLE, 
  18.             PyArray_CFLOAT, PyArray_CDOUBLE,
  19.             PyArray_OBJECT,
  20.             PyArray_NTYPES, PyArray_NOTYPE};
  21.  
  22. typedef void (PyArray_VectorUnaryFunc) (char *, int, char *, int, int);
  23.  
  24. typedef PyObject * (PyArray_GetItemFunc) (char *);
  25. typedef int (PyArray_SetItemFunc) (PyObject *, char *);
  26.  
  27. typedef struct {
  28.   PyArray_VectorUnaryFunc *cast[PyArray_NTYPES]; /* Functions to cast to */
  29.                                /* all other types */
  30.   PyArray_GetItemFunc *getitem;
  31.   PyArray_SetItemFunc *setitem;
  32.  
  33.   int type_num, elsize;
  34.   char *one, *zero;
  35.   char type;
  36.  
  37. } PyArray_Descr;
  38.  
  39. /* Array flags */
  40. #define CONTIGUOUS 1
  41. #define OWN_DIMENSIONS 2
  42. #define OWN_STRIDES 4
  43. #define OWN_DATA 8
  44. #define SAVESPACE 16
  45.  
  46. /* type bit */
  47. #define SAVESPACEBIT 128 
  48.  
  49. typedef struct {
  50.   PyObject_HEAD
  51.   char *data;
  52.   int nd;
  53.   int *dimensions, *strides;
  54.   PyObject *base;
  55.   PyArray_Descr *descr;
  56.   int flags;
  57.   PyObject *weakreflist;
  58. } PyArrayObject;
  59.  
  60.  
  61. /*
  62.  * C API
  63.  */
  64.  
  65. /* Type definitions */
  66.  
  67. #define PyArray_Type_NUM 0
  68.  
  69. /* Function definitions */
  70.  
  71. /* The following are not intended for use in user code, only needed by umath. */
  72. /* If you write your own match library, you might want this function. */
  73. #define PyArray_SetNumericOps_RET int
  74. #define PyArray_SetNumericOps_PROTO (PyObject *)
  75. #define PyArray_SetNumericOps_NUM 1
  76.  
  77. #define PyArray_INCREF_RET int
  78. #define PyArray_INCREF_PROTO (PyArrayObject *ap)
  79. #define PyArray_INCREF_NUM 2
  80.  
  81. #define PyArray_XDECREF_RET int
  82. #define PyArray_XDECREF_PROTO (PyArrayObject *ap)
  83. #define PyArray_XDECREF_NUM 3
  84.  
  85. /* Export the array error object.  Is this a good idea?  */
  86. #define PyArrayError_RET PyObject *
  87. #define PyArrayError_PROTO (void)
  88. #define PyArrayError_NUM 4
  89.  
  90. /* Set the array print function to be a python function */
  91. #define PyArray_SetStringFunction_RET void
  92. #define PyArray_SetStringFunction_PROTO (PyObject *op, int repr)
  93. #define PyArray_SetStringFunction_NUM 5
  94.  
  95. /* Get the PyArray_Descr structure for a typecode */
  96. #define PyArray_DescrFromType_RET PyArray_Descr *
  97. #define PyArray_DescrFromType_PROTO (int)
  98. #define PyArray_DescrFromType_NUM 6
  99.  
  100. /* Cast an array to a different type */
  101. #define PyArray_Cast_RET PyObject *
  102. #define PyArray_Cast_PROTO (PyArrayObject *, int)
  103. #define PyArray_Cast_NUM 7
  104.  
  105. /* Check the type coercion rules */
  106. #define PyArray_CanCastSafely_RET int
  107. #define PyArray_CanCastSafely_PROTO (int fromtype, int totype)
  108. #define PyArray_CanCastSafely_NUM 8
  109.  
  110. /* Return the typecode to use for an object if it was an array */
  111. #define PyArray_ObjectType_RET int
  112. #define PyArray_ObjectType_PROTO (PyObject *, int)
  113. #define PyArray_ObjectType_NUM 9
  114.  
  115. #define _PyArray_multiply_list_RET int
  116. #define _PyArray_multiply_list_PROTO (int *lp, int n)
  117. #define _PyArray_multiply_list_NUM 10
  118.  
  119.  
  120. /* The following defines the C API for the array object for most users */
  121.  
  122. #define PyArray_SIZE(mp) (_PyArray_multiply_list((mp)->dimensions, (mp)->nd))
  123. #define PyArray_NBYTES(mp) ((mp)->descr->elsize * PyArray_SIZE(mp))
  124. /* Obviously this needs some work. */
  125. #define PyArray_ISCONTIGUOUS(m) ((m)->flags & CONTIGUOUS)
  126. #define PyArray_ISSPACESAVER(m) (((PyArrayObject *)m)->flags & SAVESPACE)
  127. #define PyScalarArray_Check(m) (PyArray_Check((m)) && (((PyArrayObject *)(m))->nd == 0))
  128.  
  129. /* Return the size in number of items of an array */
  130. #define PyArray_Size_RET int
  131. #define PyArray_Size_PROTO (PyObject *)
  132. #define PyArray_Size_NUM 11
  133.  
  134.  
  135. /* Array creation functions */
  136. /* new_array = PyArray_FromDims(n_dimensions, dimensions[n_dimensions], item_type); */
  137. #define PyArray_FromDims_RET PyObject *
  138. #define PyArray_FromDims_PROTO (int, int *, int)
  139. #define PyArray_FromDims_NUM 12
  140.  
  141. /* array_from_existing_data = PyArray_FromDimsAndData(n_dims, dims[n_dims], item_type, old_data); */
  142. /* WARNING: using PyArray_FromDimsAndData is not reccommended!  It should only be used to refer to */
  143. /* global arrays that will never be freed (like FORTRAN common blocks). */
  144. #define PyArray_FromDimsAndData_RET PyObject *
  145. #define PyArray_FromDimsAndData_PROTO (int, int *, int, char *)
  146. #define PyArray_FromDimsAndData_NUM 13
  147.  
  148. /* Initialize from a python object. */
  149.  
  150. /* PyArray_ContiguousFromObject(object, typecode, min_dimensions, max_dimensions) */
  151. /* if max_dimensions = 0, then any number of dimensions are allowed. */
  152. /* If you want an exact number of dimensions, you should use max_dimensions */
  153. /* = min_dimensions. */
  154.  
  155. #define PyArray_ContiguousFromObject_RET PyObject *
  156. #define PyArray_ContiguousFromObject_PROTO (PyObject *, int, int, int)
  157. #define PyArray_ContiguousFromObject_NUM 14
  158.  
  159. /* Same as contiguous, except guarantees a copy of the original data */
  160. #define PyArray_CopyFromObject_RET PyObject *
  161. #define PyArray_CopyFromObject_PROTO (PyObject *, int, int, int)
  162. #define PyArray_CopyFromObject_NUM 15
  163.  
  164. /* Shouldn't be used unless you know what you're doing and are not scared by discontiguous arrays */
  165. #define PyArray_FromObject_RET PyObject *
  166. #define PyArray_FromObject_PROTO (PyObject *, int, int, int)
  167. #define PyArray_FromObject_NUM 16
  168.  
  169. /* Return either an array, or if passed a 0d array return the appropriate python scalar */
  170. #define PyArray_Return_RET PyObject *
  171. #define PyArray_Return_PROTO (PyArrayObject *)
  172. #define PyArray_Return_NUM 17
  173.  
  174. #define PyArray_Reshape_RET PyObject *
  175. #define PyArray_Reshape_PROTO (PyArrayObject *ap, PyObject *shape)
  176. #define PyArray_Reshape_NUM 18
  177.  
  178. #define PyArray_Copy_RET PyObject *
  179. #define PyArray_Copy_PROTO (PyArrayObject *ap)
  180. #define PyArray_Copy_NUM 19
  181.  
  182. #define PyArray_Take_RET PyObject *
  183. #define PyArray_Take_PROTO (PyObject *ap, PyObject *items, int axis)
  184. #define PyArray_Take_NUM 20
  185.  
  186. /*Getting arrays in various useful forms. */
  187. #define PyArray_As1D_RET int
  188. #define PyArray_As1D_PROTO (PyObject **op, char **ptr, int *d1, int typecode)
  189. #define PyArray_As1D_NUM 21
  190.  
  191. #define PyArray_As2D_RET int
  192. #define PyArray_As2D_PROTO (PyObject **op, char ***ptr, int *d1, int *d2, int typecode)
  193. #define PyArray_As2D_NUM 22
  194.  
  195. #define PyArray_Free_RET int
  196. #define PyArray_Free_PROTO (PyObject *op, char *ptr)
  197. #define PyArray_Free_NUM 23
  198.  
  199. /* array_from_existing_data = PyArray_FromDimsAndDataAndDescr(n_dims, dims[n_dims], descr, old_data); */
  200. /* WARNING: using PyArray_FromDimsAndDataAndDescr is not reccommended!  It should only be used to refer to */
  201. /* global arrays that will never be freed (like FORTRAN common blocks). */
  202. #define PyArray_FromDimsAndDataAndDescr_RET PyObject *
  203. #define PyArray_FromDimsAndDataAndDescr_PROTO (int, int *, PyArray_Descr *, char *)
  204. #define PyArray_FromDimsAndDataAndDescr_NUM 24
  205.  
  206. #define PyArray_Converter_RET int
  207. #define PyArray_Converter_PROTO (PyObject *, PyObject **)
  208. #define PyArray_Converter_NUM 25
  209.  
  210. #define PyArray_Put_RET PyObject *
  211. #define PyArray_Put_PROTO (PyObject *ap, PyObject *items, PyObject* values)
  212. #define PyArray_Put_NUM 26
  213.  
  214. #define PyArray_PutMask_RET PyObject *
  215. #define PyArray_PutMask_PROTO (PyObject *ap, PyObject *mask, PyObject* values)
  216. #define PyArray_PutMask_NUM 27
  217.  
  218. #define PyArray_CopyArray_RET int
  219. #define PyArray_CopyArray_PROTO (PyArrayObject *dest, PyArrayObject *src)
  220. #define PyArray_CopyArray_NUM 28
  221.  
  222. #define PyArray_ValidType_RET int
  223. #define PyArray_ValidType_PROTO (int type)
  224. #define PyArray_ValidType_NUM 29
  225.  
  226. /* Total number of C API pointers */
  227. #define PyArray_API_pointers 30
  228.  
  229.  
  230. #ifdef _ARRAY_MODULE
  231.  
  232. extern PyTypeObject PyArray_Type;
  233. #define PyArray_Check(op) ((op)->ob_type == &PyArray_Type)
  234.  
  235. extern PyArray_SetNumericOps_RET PyArray_SetNumericOps \
  236.        PyArray_SetNumericOps_PROTO;
  237. extern PyArray_INCREF_RET PyArray_INCREF PyArray_INCREF_PROTO;
  238. extern PyArray_XDECREF_RET PyArray_XDECREF PyArray_XDECREF_PROTO;
  239. extern PyArrayError_RET PyArrayError PyArrayError_PROTO;
  240. extern PyArray_SetStringFunction_RET PyArray_SetStringFunction \
  241.        PyArray_SetStringFunction_PROTO;
  242. extern PyArray_DescrFromType_RET PyArray_DescrFromType \
  243.        PyArray_DescrFromType_PROTO;
  244. extern PyArray_Cast_RET PyArray_Cast PyArray_Cast_PROTO;
  245. extern PyArray_CanCastSafely_RET PyArray_CanCastSafely \
  246.        PyArray_CanCastSafely_PROTO;
  247. extern PyArray_ObjectType_RET PyArray_ObjectType PyArray_ObjectType_PROTO;
  248. extern _PyArray_multiply_list_RET _PyArray_multiply_list \
  249.        _PyArray_multiply_list_PROTO;
  250. extern PyArray_Size_RET PyArray_Size PyArray_Size_PROTO;
  251. extern PyArray_FromDims_RET PyArray_FromDims PyArray_FromDims_PROTO;
  252. extern PyArray_FromDimsAndData_RET PyArray_FromDimsAndData \
  253.        PyArray_FromDimsAndData_PROTO;
  254. extern PyArray_FromDimsAndDataAndDescr_RET PyArray_FromDimsAndDataAndDescr \
  255.        PyArray_FromDimsAndDataAndDescr_PROTO;
  256. extern PyArray_ContiguousFromObject_RET PyArray_ContiguousFromObject \
  257.        PyArray_ContiguousFromObject_PROTO;
  258. extern PyArray_CopyFromObject_RET PyArray_CopyFromObject \
  259.        PyArray_CopyFromObject_PROTO;
  260. extern PyArray_FromObject_RET PyArray_FromObject PyArray_FromObject_PROTO;
  261. extern PyArray_Return_RET PyArray_Return PyArray_Return_PROTO;
  262. extern PyArray_Reshape_RET PyArray_Reshape PyArray_Reshape_PROTO;
  263. extern PyArray_Copy_RET PyArray_Copy PyArray_Copy_PROTO;
  264. extern PyArray_Take_RET PyArray_Take PyArray_Take_PROTO;
  265. extern PyArray_As1D_RET PyArray_As1D PyArray_As1D_PROTO;
  266. extern PyArray_As2D_RET PyArray_As2D PyArray_As2D_PROTO;
  267. extern PyArray_Free_RET PyArray_Free PyArray_Free_PROTO;
  268. extern PyArray_Converter_RET PyArray_Converter PyArray_Converter_PROTO;
  269. extern PyArray_Put_RET PyArray_Put PyArray_Put_PROTO;
  270. extern PyArray_PutMask_RET PyArray_PutMask PyArray_PutMask_PROTO;
  271. extern PyArray_CopyArray_RET PyArray_CopyArray PyArray_CopyArray_PROTO;
  272. extern PyArray_ValidType_RET PyArray_ValidType PyArray_ValidType_PROTO;
  273.  
  274. #else
  275.  
  276. #if defined(PY_ARRAY_UNIQUE_SYMBOL)
  277. #define PyArray_API PY_ARRAY_UNIQUE_SYMBOL
  278. #endif
  279.  
  280. /* C API address pointer */ 
  281. #if defined(NO_IMPORT) || defined(NO_IMPORT_ARRAY)
  282. extern void **PyArray_API;
  283. #else
  284. #if defined(PY_ARRAY_UNIQUE_SYMBOL)
  285. void **PyArray_API;
  286. #else
  287. static void **PyArray_API;
  288. #endif
  289. #endif
  290.  
  291. #define PyArray_Check(op) \
  292.    ((op)->ob_type == (PyTypeObject *)PyArray_API[PyArray_Type_NUM])
  293. #define PyArray_Type *(PyTypeObject *)PyArray_API[PyArray_Type_NUM]
  294.  
  295. #define PyArray_SetNumericOps \
  296.   (*(PyArray_SetNumericOps_RET (*)PyArray_SetNumericOps_PROTO) \
  297.    PyArray_API[PyArray_SetNumericOps_NUM])
  298. #define PyArray_INCREF \
  299.   (*(PyArray_INCREF_RET (*)PyArray_INCREF_PROTO) \
  300.    PyArray_API[PyArray_INCREF_NUM])
  301. #define PyArray_XDECREF \
  302.   (*(PyArray_XDECREF_RET (*)PyArray_XDECREF_PROTO) \
  303.    PyArray_API[PyArray_XDECREF_NUM])
  304. #define PyArrayError \
  305.   (*(PyArrayError_RET (*)PyArrayError_PROTO) \
  306.    PyArray_API[PyArrayError_NUM])
  307. #define PyArray_SetStringFunction \
  308.   (*(PyArray_SetStringFunction_RET (*)PyArray_SetStringFunction_PROTO) \
  309.    PyArray_API[PyArray_SetStringFunction_NUM])
  310. #define PyArray_DescrFromType \
  311.   (*(PyArray_DescrFromType_RET (*)PyArray_DescrFromType_PROTO) \
  312.    PyArray_API[PyArray_DescrFromType_NUM])
  313. #define PyArray_Cast \
  314.   (*(PyArray_Cast_RET (*)PyArray_Cast_PROTO) \
  315.    PyArray_API[PyArray_Cast_NUM])
  316. #define PyArray_CanCastSafely \
  317.   (*(PyArray_CanCastSafely_RET (*)PyArray_CanCastSafely_PROTO) \
  318.    PyArray_API[PyArray_CanCastSafely_NUM])
  319. #define PyArray_ObjectType \
  320.   (*(PyArray_ObjectType_RET (*)PyArray_ObjectType_PROTO) \
  321.    PyArray_API[PyArray_ObjectType_NUM])
  322. #define _PyArray_multiply_list \
  323.   (*(_PyArray_multiply_list_RET (*)_PyArray_multiply_list_PROTO) \
  324.    PyArray_API[_PyArray_multiply_list_NUM])
  325. #define PyArray_Size \
  326.   (*(PyArray_Size_RET (*)PyArray_Size_PROTO) \
  327.    PyArray_API[PyArray_Size_NUM])
  328. #define PyArray_FromDims \
  329.   (*(PyArray_FromDims_RET (*)PyArray_FromDims_PROTO) \
  330.    PyArray_API[PyArray_FromDims_NUM])
  331. #define PyArray_FromDimsAndData \
  332.   (*(PyArray_FromDimsAndData_RET (*)PyArray_FromDimsAndData_PROTO) \
  333.    PyArray_API[PyArray_FromDimsAndData_NUM])
  334. #define PyArray_FromDimsAndDataAndDescr \
  335.   (*(PyArray_FromDimsAndDataAndDescr_RET (*)PyArray_FromDimsAndDataAndDescr_PROTO) \
  336.    PyArray_API[PyArray_FromDimsAndDataAndDescr_NUM])
  337. #define PyArray_ContiguousFromObject \
  338.   (*(PyArray_ContiguousFromObject_RET (*)PyArray_ContiguousFromObject_PROTO) \
  339.    PyArray_API[PyArray_ContiguousFromObject_NUM])
  340. #define PyArray_CopyFromObject \
  341.   (*(PyArray_CopyFromObject_RET (*)PyArray_CopyFromObject_PROTO) \
  342.    PyArray_API[PyArray_CopyFromObject_NUM])
  343. #define PyArray_FromObject \
  344.   (*(PyArray_FromObject_RET (*)PyArray_FromObject_PROTO) \
  345.    PyArray_API[PyArray_FromObject_NUM])
  346. #define PyArray_Return \
  347.   (*(PyArray_Return_RET (*)PyArray_Return_PROTO) \
  348.    PyArray_API[PyArray_Return_NUM])
  349. #define PyArray_Reshape \
  350.   (*(PyArray_Reshape_RET (*)PyArray_Reshape_PROTO) \
  351.    PyArray_API[PyArray_Reshape_NUM])
  352. #define PyArray_Copy \
  353.   (*(PyArray_Copy_RET (*)PyArray_Copy_PROTO) \
  354.    PyArray_API[PyArray_Copy_NUM])
  355. #define PyArray_Take \
  356.   (*(PyArray_Take_RET (*)PyArray_Take_PROTO) \
  357.    PyArray_API[PyArray_Take_NUM])
  358. #define PyArray_As1D \
  359.   (*(PyArray_As1D_RET (*)PyArray_As1D_PROTO) \
  360.    PyArray_API[PyArray_As1D_NUM])
  361. #define PyArray_As2D \
  362.   (*(PyArray_As2D_RET (*)PyArray_As2D_PROTO) \
  363.    PyArray_API[PyArray_As2D_NUM])
  364. #define PyArray_Free \
  365.   (*(PyArray_Free_RET (*)PyArray_Free_PROTO) \
  366.    PyArray_API[PyArray_Free_NUM])
  367. #define PyArray_Converter \
  368.   (*(PyArray_Converter_RET (*)PyArray_Converter_PROTO) \
  369.    PyArray_API[PyArray_Converter_NUM])
  370. #define PyArray_Put \
  371.   (*(PyArray_Put_RET (*)PyArray_Put_PROTO) \
  372.    PyArray_API[PyArray_Put_NUM])
  373. #define PyArray_PutMask \
  374.   (*(PyArray_PutMask_RET (*)PyArray_PutMask_PROTO) \
  375.    PyArray_API[PyArray_PutMask_NUM])
  376. #define PyArray_CopyArray \
  377.   (*(PyArray_CopyArray_RET (*)PyArray_CopyArray_PROTO) \
  378.    PyArray_API[PyArray_CopyArray_NUM])
  379. #define PyArray_ValidType \
  380.   (*(PyArray_ValidType_RET (*)PyArray_ValidType_PROTO) \
  381.    PyArray_API[PyArray_ValidType_NUM])
  382.  
  383. #define import_array() \
  384. { \
  385.   PyObject *numpy = PyImport_ImportModule("_numpy"); \
  386.   if (numpy != NULL) { \
  387.     PyObject *module_dict = PyModule_GetDict(numpy); \
  388.     PyObject *c_api_object = PyDict_GetItemString(module_dict, "_ARRAY_API"); \
  389.     if (PyCObject_Check(c_api_object)) { \
  390.       PyArray_API = (void **)PyCObject_AsVoidPtr(c_api_object); \
  391.     } \
  392.   } \
  393. }
  394.  
  395. #endif
  396.  
  397.  
  398. #ifdef __cplusplus
  399. }
  400. #endif
  401. #endif /* !Py_ARRAYOBJECT_H */
  402.